package com.ruoyi.generator.service;

import com.ruoyi.generator.entity.Equipment;
import com.ruoyi.generator.entity.File;
import com.ruoyi.generator.entity.ImageFile;
import com.ruoyi.generator.entity.PlanAssociation;
import com.ruoyi.generator.entity.bo.PlanScheduleInfoBO;
import com.ruoyi.generator.entity.vo.WorkOrderVO;
import com.ruoyi.generator.mapper.AppMapper;
import com.ruoyi.generator.mapper.PlanScheduleMapper;
import com.ruoyi.generator.mapper.WorkOrderMapper;
import com.ruoyi.generator.vo.MaintenanceAppVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public  class WorkOrderServiceImpl implements WorkOrderService {


    @Autowired
    private WorkOrderMapper workOrderMapper;


    @Override
    public void createWorkOrder(WorkOrderVO workOrderVO) {
        //生成工单id
        String workOrderId = "WORK_ORDER_" +workOrderVO.getEquipmentId()+"_"+LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));

        for (ImageFile imageFile : workOrderVO.getImages()){
            File file = new File();
            file.setFilePath(imageFile.getName());
            file.setWorkOrderId(workOrderId);
            file.setFileId(String.valueOf(imageFile.getUid()));
            workOrderMapper.insertFile(file);
        }
        workOrderVO.setWorkOrderId(workOrderId);
        workOrderMapper.createWorkOrder(workOrderVO);
    }
}
